<script setup lang="ts">
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'
import 'echarts-liquidfill'

const chartsRef = ref<any>()

const initCharts = () => {
  const myCharts = echarts.init(chartsRef.value)

  const itemColor1 = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
      offset: 0,
      color: 'rgb(0, 221, 255)',
    },
    {
      offset: 1,
      color: 'rgb(77, 119, 255)',
    },
  ])

  const itemColor2 = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
      offset: 0,
      color: 'rgb(255, 191, 0)',
    },
    {
      offset: 1,
      color: 'rgb(224, 62, 76)',
    },
  ])

  const options = {
    color: [itemColor1, itemColor2],
    title: {
      show: false,
    },
    textStyle: {
      color: '#fff',
    },
    legend: {
      data: ['故宫', '长城'],
      right: '5',
      orient: 'vertical',
      textStyle: {
        color: '#fff',
      },
    },
    tooltip: {
      type: 'item',
    },
    radar: {
      // shape: 'circle',
      radius: '80%',
      center: ['50%', '55%'],
      indicator: [
        { name: '门票', max: 6500 },
        { name: '酒店', max: 16000 },
        { name: '购物', max: 30000 },
        { name: '交通', max: 50000 },
        { name: '服务', max: 30000 },
      ],
    },
    series: [
      {
        name: '',
        type: 'radar',
        data: [
          {
            value: [4200, 3000, 20000, 35000, 18000],
            name: '故宫',
            areaStyle: { color: itemColor1 },
          },
          {
            value: [5000, 14000, 28000, 26000, 21000],
            name: '长城',
            areaStyle: { color: itemColor2 },
          },
        ],
      },
    ],
  }
  myCharts.setOption(options)
}
onMounted(() => {
  initCharts()
})
</script>

<template>
  <div class="data">
    <div class="top">
      <p class="title">消费指数分布</p>
    </div>
    <div class="charts" ref="chartsRef"></div>
  </div>
</template>

<style scoped lang="scss">
$title-height: 32px;

.data {
  flex: 1;

  .top {
    margin-bottom: 40px;
    font-size: 20px;
    line-height: $title-height;
    color: #fff;

    .title {
      &::after {
        top: $title-height;
        left: 0;
        display: block;
        width: 68px;
        height: 7px;
        content: '';
        background: url('@/assets/images/data_screen/figure.png') no-repeat;
        background-size: cover;
      }
    }
  }

  .charts {
    align-items: center;
    width: 100%;
    height: 220px;
  }
}
</style>
